Extract.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use client";
  2. import { CashbackTypes } from "@/api/cashback";
  3. import { server } from "@/utils/client";
  4. import { timeFormat } from "@/utils/methods";
  5. import { Toast } from "antd-mobile";
  6. import { useAnimate } from "framer-motion";
  7. import { useTranslations } from "next-intl";
  8. import styles from "./style.module.scss";
  9. interface Props {
  10. local: string;
  11. cashbackInfo: CashbackTypes;
  12. }
  13. const Extract = (props: Props) => {
  14. const { local, cashbackInfo } = props;
  15. const [scope, animate] = useAnimate();
  16. const t = useTranslations();
  17. const getCashbackGiveApi = () => {
  18. if (cashbackInfo.status !== "pending") {
  19. animate(
  20. scope.current,
  21. { color: ["#000", "#ffaa30", "#000"] },
  22. {
  23. duration: 0.6,
  24. repeat: 2,
  25. repeatType: "loop",
  26. }
  27. );
  28. return;
  29. }
  30. if (cashbackInfo.amount === 0) {
  31. return;
  32. }
  33. return server
  34. .post({
  35. url: "/v1/api/front/activity_cash_give",
  36. })
  37. .then((res) => {
  38. if (res.code === 200) Toast.show(t(`code.200`));
  39. })
  40. .catch((error) => {
  41. Toast.show(t(`code.${error.data.code}`));
  42. });
  43. };
  44. return (
  45. <>
  46. <ul className={"mb-[0.2rem]"}>
  47. <li className={styles.timelineItem}>
  48. <p className={"text-[20px] text-[#a3a3a3]"}>{t("cashback.beforeTips")} </p>
  49. <div className={`${styles.timelineMarker} before:bg-[#fbc110]`}></div>
  50. <div className={styles.timelineContent}>
  51. <span className={"text-[0.12rem] text-[#6c6c6c]"}>
  52. {timeFormat(cashbackInfo.last_period.start_time, local)} ~{" "}
  53. {timeFormat(cashbackInfo.last_period.end_time, local)}
  54. </span>
  55. </div>
  56. </li>
  57. <li className={styles.timelineItem}>
  58. <p className={"text-[20px] text-[#a3a3a3]"}>{t("cashback.afterTips")} </p>
  59. <div className={`${styles.timelineMarker} before:bg-[#9ae0b9]`}></div>
  60. <div>
  61. <span className={"text-[0.12rem] text-[#6c6c6c]"} ref={scope}>
  62. {timeFormat(cashbackInfo.next_period.start_time, local)} ~{" "}
  63. {timeFormat(cashbackInfo.next_period.end_time, local)}
  64. </span>
  65. </div>
  66. </li>
  67. </ul>
  68. <div
  69. className={
  70. "rounded bg-gradient-to-b from-[#ff9b23] to-[#ff7308]" +
  71. " flex h-[0.3472rem] items-center justify-center font-bold text-[#fff]"
  72. }
  73. onClick={getCashbackGiveApi}
  74. >
  75. {t("cashback.receiveButton")}
  76. </div>
  77. </>
  78. );
  79. };
  80. export default Extract;